//app.js
App({
  globalData:{
    open_id: '',
    name: '',
    photo: ''
  },

  onLaunch: function () {
    var that = this
    
    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力')
    } else {
      wx.cloud.init({
        env: 'jall-tx9q3',
        traceUser: true,
      })
    }
    wx.getSetting({
      //已授权
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          wx.getUserInfo({
            success: function (res) {
              that.globalData.name = res.userInfo.nickName
              that.globalData.photo = res.userInfo.avatarUrl
            }
          });
        }
        //没有授权
        else{
          wx.reLaunch({
            url: '../login/login',
          })
        }
      }
    })
    wx.cloud.callFunction({
      name: 'login'
    }).then(res => {
      console.log(res.result.openid)
      that.globalData.open_id = res.result.openid
    })
  }
})
